﻿namespace Agent
{
    using Hardcodet.Wpf.TaskbarNotification;
    using Microsoft.Win32;
    using OpenVPN;
    using OpenVPN.States;
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Linq;
    using System.Net;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading;
    using System.Timers;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Input;
    using System.Windows.Markup;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using TheSafety;

    [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
    public class MainWindow : Window, IComponentConnector
    {
        private const bool a = true;
        [CompilerGenerated]
        private static SendOrPostCallback aa;
        [CompilerGenerated]
        private static SendOrPostCallback ab;
        [CompilerGenerated]
        private static SendOrPostCallback ac;
        [CompilerGenerated]
        private static SendOrPostCallback ad;
        [CompilerGenerated]
        private static PropertyChangedCallback ae;
        private SynchronizationContext b;
        public static readonly DependencyProperty c;
        private AgentMessageEventArgs d;
        internal Grid e;
        internal TaskbarIcon f;
        internal TaskbarIcon g;
        internal MenuItem h;
        internal MenuItem i;
        internal MenuItem j;
        internal Image k;
        internal Label l;
        internal Label m;
        internal TextBox n;
        internal PasswordBox o;
        internal TextBox p;
        internal Image q;
        internal ComboBox r;
        internal CheckBox s;
        internal CheckBox t;
        internal TextBlock u;
        internal TextBlock v;
        internal Button w;
        internal CheckBox x;
        internal TextBox y;
        private bool z;

        static MainWindow()
        {
            if (ae == null)
            {
                ae = new PropertyChangedCallback(MainWindow.a);
            }
            c = DependencyProperty.Register("CurrentIP", typeof(string), typeof(MainWindow), new FrameworkPropertyMetadata(ae));
        }

        public MainWindow()
        {
            this.InitializeComponent();
            ConfigManager.a("flusher", 30000.0, new System.Action(this.i));
            string str = string.IsNullOrWhiteSpace(ConfigManager.b("mylang")) ? ConfigManager.l() : ConfigManager.b("mylang");
            int num = 0;
            foreach (KeyValuePair<KeyValuePair<string, string>, string> pair in e.a())
            {
                ComboBoxItem newItem = new ComboBoxItem {
                    Content = pair.Value,
                    Tag = pair.Key
                };
                this.r.Items.Add(newItem);
                if ((str != null) && (str == pair.Key.Value))
                {
                    this.r.SelectedIndex = num;
                }
                num++;
            }
            if (this.r.SelectedIndex == -1)
            {
                this.r.SelectedIndex = 0;
            }
            e.a((KeyValuePair<string, string>) (this.r.Items[this.r.SelectedIndex] as ComboBoxItem).Tag);
            this.h();
            ConfigManager.a(this);
            ConfigManager.e = (System.Action) Delegate.Combine(ConfigManager.e, new System.Action(this.e));
        }

        [CompilerGenerated]
        private void a()
        {
            if (ConfigManager.a())
            {
                <>c__DisplayClass14 class2;
                string a = new WebClient().DownloadString("https://thesafety.us/billing/gui/ip.php");
                a = a.Trim(new char[] { ' ', '\t', '\r', '\n' });
                if (ConfigManager.o() != null)
                {
                    this.b.Send(new SendOrPostCallback(class2.d), null);
                }
                this.b.Send(new SendOrPostCallback(class2.c), null);
            }
        }

        [CompilerGenerated]
        private void a(object A_0)
        {
            this.g.a((ImageSource) new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/yellow.ico")));
        }

        [EditorBrowsable(EditorBrowsableState.Never), DebuggerNonUserCode]
        private void a(int A_0, object A_1)
        {
            switch (A_0)
            {
                case 1:
                    ((MainWindow) A_1).Loaded += new RoutedEventHandler(this.Window_Loaded);
                    ((MainWindow) A_1).KeyUp += new KeyEventHandler(this.Window_KeyUp);
                    ((MainWindow) A_1).Closing += new CancelEventHandler(this.Window_Closing);
                    ((MainWindow) A_1).StateChanged += new EventHandler(this.Window_StateChanged);
                    return;

                case 2:
                    this.e = (Grid) A_1;
                    return;

                case 3:
                    this.f = (TaskbarIcon) A_1;
                    return;

                case 4:
                    this.g = (TaskbarIcon) A_1;
                    return;

                case 5:
                    this.h = (MenuItem) A_1;
                    this.h.Click += new RoutedEventHandler(this.MenuItemShow_Click);
                    return;

                case 6:
                    this.i = (MenuItem) A_1;
                    this.i.Click += new RoutedEventHandler(this.buttonUpdateIP_Click);
                    return;

                case 7:
                    this.j = (MenuItem) A_1;
                    this.j.Click += new RoutedEventHandler(this.MenuItemExit_Click);
                    return;

                case 8:
                    this.k = (Image) A_1;
                    return;

                case 9:
                    this.l = (Label) A_1;
                    return;

                case 10:
                    this.m = (Label) A_1;
                    return;

                case 11:
                    this.n = (TextBox) A_1;
                    this.n.GotFocus += new RoutedEventHandler(this.txtLogin_GotFocus);
                    this.n.PreviewMouseDown += new MouseButtonEventHandler(this.txtLogin_PreviewMouseDown);
                    return;

                case 12:
                    this.o = (PasswordBox) A_1;
                    this.o.GotFocus += new RoutedEventHandler(this.txtPassword_GotFocus);
                    this.o.PreviewMouseDown += new MouseButtonEventHandler(this.txtPassword_PreviewMouseDown);
                    return;

                case 13:
                    this.p = (TextBox) A_1;
                    return;

                case 14:
                    this.q = (Image) A_1;
                    this.q.MouseLeftButtonUp += new MouseButtonEventHandler(this.ShowPassword_Click);
                    return;

                case 15:
                    this.r = (ComboBox) A_1;
                    this.r.SelectionChanged += new SelectionChangedEventHandler(this.ddlLang_SelectionChanged);
                    return;

                case 0x10:
                    this.s = (CheckBox) A_1;
                    return;

                case 0x11:
                    this.t = (CheckBox) A_1;
                    return;

                case 0x12:
                    this.u = (TextBlock) A_1;
                    this.u.MouseLeftButtonUp += new MouseButtonEventHandler(this.lblForgot_MouseLeftButtonUp);
                    return;

                case 0x13:
                    this.v = (TextBlock) A_1;
                    this.v.MouseLeftButtonUp += new MouseButtonEventHandler(this.lblRegistration_MouseLeftButtonUp);
                    return;

                case 20:
                    this.w = (Button) A_1;
                    this.w.Click += new RoutedEventHandler(this.btnLogin_click);
                    return;

                case 0x15:
                    this.x = (CheckBox) A_1;
                    this.x.Click += new RoutedEventHandler(this.chkOfflineMode_Click);
                    return;

                case 0x16:
                    this.y = (TextBox) A_1;
                    this.y.GotFocus += new RoutedEventHandler(this.txtPasswordO_GotFocus);
                    this.y.PreviewMouseDown += new MouseButtonEventHandler(this.txtPasswordO_PreviewMouseDown);
                    return;
            }
            this.z = true;
        }

        private void a(object A_0, AgentExitEventArgs A_1)
        {
            AgentUser.a((AgentUser) null);
            base.Show();
            ConfigManager.o().Visibility = Visibility.Collapsed;
            ConfigManager.f();
            base.WindowState = WindowState.Normal;
            base.Activate();
            this.g.a((ImageSource) new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/red.ico")));
            this.g.r();
        }

        private void a(object A_0, AgentMessageEventArgs A_1)
        {
            BalloonIcon none = BalloonIcon.None;
            switch (A_1.c())
            {
                case NotificationType.Info:
                    none = BalloonIcon.Info;
                    break;

                case NotificationType.Error:
                    none = BalloonIcon.Error;
                    break;
            }
            this.g.a(none.ToString(), A_1.d(), none);
        }

        [DebuggerNonUserCode]
        internal Delegate a(Type A_0, string A_1)
        {
            return Delegate.CreateDelegate(A_0, this, A_1);
        }

        [CompilerGenerated]
        private static void a(DependencyObject A_0, DependencyPropertyChangedEventArgs A_1)
        {
        }

        private void AddTmpFileLog(object A_0, TmpFileLogEventArgs A_1)
        {
            SendOrPostCallback d = null;
            string a = "";
            NotificationType error = NotificationType.Error;
            if (A_1.a() != null)
            {
                foreach (string str in A_1.a().Split(new char[] { '\n' }))
                {
                    if (str.Contains("failed, will try again in 5 seconds: Network is unreachable"))
                    {
                        a = e.c("ovpn_error_net");
                    }
                    else if (str.Contains("failed, will try again in 5 seconds: Invalid argument"))
                    {
                        a = e.c("ovpn_error_argument");
                    }
                    else if (str.Contains("failed, will try again in 5 seconds: Connection timed out"))
                    {
                        a = e.c("ovpn_error_time_out");
                    }
                    else if (str.Contains("Error opening 'Auth' auth file:"))
                    {
                        a = e.c("ovpn_error_auth_file");
                    }
                    else if (str.Contains("AUTH: Received AUTH_FAILED control message"))
                    {
                        a = e.c("ovpn_error_auth");
                    }
                    else if (str.Contains("Error opening file client.p12"))
                    {
                        a = e.c("ovpn_error_client.p12");
                    }
                    else if (str.Contains("Cannot open file key file 'ta.key'"))
                    {
                        a = e.c("ovpn_error_ta.key");
                    }
                    else if (str.Contains("Cannot load certificate file client.crt"))
                    {
                        a = e.c("ovpn_error_client.crt");
                    }
                    else if (str.Contains("All TAP-Win32 adapters on this system are currently in use"))
                    {
                        a = e.c("ovpn_error_tap");
                    }
                    else if (str.Contains("ERROR: Windows route add command failed: returned error code 1"))
                    {
                        a = e.c("ovpn_error_win");
                    }
                    else if (str.Contains("Initialization Sequence Completed With Errors"))
                    {
                        a = e.c("ovpn_error_init");
                    }
                    else
                    {
                        if (str.Contains("Initialization Sequence Completed"))
                        {
                            if (!(ConfigManager.b("dontshownotification") == "0"))
                            {
                                goto Label_02B7;
                            }
                            error = NotificationType.Info;
                            a = e.c("ovpn_info_init");
                            a = a + Environment.NewLine;
                            if (d == null)
                            {
                                <>c__DisplayClass47 class2;
                                d = new SendOrPostCallback(class2.b);
                            }
                            this.b.Send(d, null);
                            a = a + Environment.NewLine;
                            a = a + e.c("MyIp");
                            AgentMessageEventArgs args = new AgentMessageEventArgs();
                            args.a(error);
                            args.a(a);
                            this.d = args;
                            break;
                        }
                        if (str.Contains("Unknown mistake."))
                        {
                            a = e.c("ovpn_error_x");
                        }
                    }
                Label_02B7:
                    if (!string.IsNullOrWhiteSpace(a))
                    {
                        NotifyItem item = new NotifyItem();
                        item.b(a);
                        item.a(NotifyState.New);
                        item.a(a);
                        item.a(error);
                        NotifyManager.a(item);
                        break;
                    }
                }
            }
        }

        [CompilerGenerated]
        private void b()
        {
            this.b.Send(new SendOrPostCallback(this.r), null);
        }

        [CompilerGenerated]
        private void b(object A_0)
        {
            this.g.a((ImageSource) new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/yellow.ico")));
        }

        protected void b(string A_0)
        {
            if (this.d != null)
            {
                this.d.a(this.d.d() + A_0);
                this.b(null, this.d);
                this.d = null;
            }
        }

        public void b(object A_0, AgentMessageEventArgs A_1)
        {
            new Thread(new ParameterizedThreadStart(this.q)) { IsBackground = true }.Start(A_1);
        }

        private void btnLogin_click(object A_0, RoutedEventArgs A_1)
        {
            ConfigManager.b(this.x.IsChecked.Value);
            new Thread(new ParameterizedThreadStart(this.p)) { IsBackground = true }.Start(new string[] { this.n.Text, this.d() });
            KeyValuePair<string, string> tag = (KeyValuePair<string, string>) (this.r.SelectedValue as ComboBoxItem).Tag;
            ConfigManager.a("mylang", tag.Value);
        }

        private void button_NotePadExited(object A_0, EventArgs A_1)
        {
            try
            {
                VPNConfig config = VPNConfig.e(ConfigManager.q() + "/vpn.exe", (A_0 as ConnectionButton).g().h(), 1);
                (A_0 as ConnectionButton).a(config);
                (A_0 as ConnectionButton).g().l().State.StateChanged += new EventHandler<StateChangedEventArgs>(this.VPNConnection_StateChanged);
                (A_0 as ConnectionButton).g().b = new EventHandler<TmpFileLogEventArgs>(this.AddTmpFileLog);
                (A_0 as ConnectionButton).k();
                (A_0 as ConnectionButton).a(new NotePadExited(this.button_NotePadExited));
            }
            catch (Exception exception)
            {
                ConfigManager.a("button_NotePadExited", exception);
            }
        }

        private void buttonUpdateIP_Click(object A_0, RoutedEventArgs A_1)
        {
            new Thread(new ThreadStart(this.a)) { IsBackground = true }.Start();
        }

        [CompilerGenerated]
        private void c()
        {
            this.b.Send(new SendOrPostCallback(this.s), null);
        }

        [CompilerGenerated]
        private void c(object A_0)
        {
            this.g.a((ImageSource) new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/red.ico")));
        }

        private void chkOfflineMode_Click(object A_0, RoutedEventArgs A_1)
        {
            this.n.IsEnabled = this.o.IsEnabled = this.y.IsEnabled = this.q.IsEnabled = this.p.IsEnabled = this.s.IsEnabled = !this.x.IsChecked.Value;
        }

        private string d()
        {
            if (this.o.Visibility == Visibility.Visible)
            {
                return this.o.Password;
            }
            return this.y.Text;
        }

        [CompilerGenerated]
        private void d(object A_0)
        {
            this.g.a((ImageSource) new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/green.ico")));
        }

        private void ddlLang_SelectionChanged(object A_0, SelectionChangedEventArgs A_1)
        {
            e.a((KeyValuePair<string, string>) (this.r.SelectedItem as ComboBoxItem).Tag);
            this.h();
        }

        private void e()
        {
            ConfigManager.a(new EventHandler<StateChangedEventArgs>(this.VPNConnection_StateChanged), new EventHandler<TmpFileLogEventArgs>(this.AddTmpFileLog), new EventHandler<NeedLoginAndPasswordEventArgs>(this.NeedPasswordAndLogin));
            ConfigManager.a(new NotePadExited(this.button_NotePadExited));
        }

        [CompilerGenerated]
        private void e(object A_0)
        {
            this.g.a((ImageSource) new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/yellow.ico")));
        }

        private void f()
        {
            Func<ConnectionButton, bool> predicate = null;
            Func<ConnectionButton, bool> func2 = null;
            <>c__DisplayClass34 class2;
            string a = ConfigManager.b("autoconnectconfig");
            if (ConfigManager.k().Count<ConnectionButton>(new Func<ConnectionButton, bool>(class2.c)) > 0)
            {
                if (predicate == null)
                {
                    predicate = new Func<ConnectionButton, bool>(class2.b);
                }
                ConfigManager.k().Where<ConnectionButton>(predicate).ToList<ConnectionButton>()[0].lblMain_MouseLeftButtonUp(null, null);
                if (func2 == null)
                {
                    func2 = new Func<ConnectionButton, bool>(class2.d);
                }
                ConfigManager.k().Where<ConnectionButton>(func2).ToList<ConnectionButton>()[0].lblMain_MouseDoubleClick(null, null);
            }
            ConfigManager.c(new System.Action(this.f));
        }

        [CompilerGenerated]
        private void f(object A_0)
        {
            this.e.IsEnabled = true;
        }

        private void g()
        {
            base.WindowState = WindowState.Minimized;
            ConfigManager.a(new MainMenuPanel());
            ConfigManager.o().b(new AgentMessageHandler(this.a));
            ConfigManager.o().b(new AgentExitHandler(this.a));
            this.g.r();
            this.g.a(ConfigManager.o(), PopupAnimation.Fade, null);
            this.g.Focus();
            ConfigManager.a("autologin", this.t.IsChecked.HasValue ? (this.t.IsChecked.Value ? "1" : "0") : "0");
            ConfigManager.a("savepass", this.s.IsChecked.HasValue ? (this.s.IsChecked.Value ? "1" : "0") : "0");
            if (this.s.IsChecked.HasValue && this.s.IsChecked.Value)
            {
                ConfigManager.a("mypass", ConfigManager.a(this.d()));
                ConfigManager.a("mylogin", ConfigManager.a(this.n.Text));
            }
        }

        [CompilerGenerated]
        private void g(object A_0)
        {
            ConfigManager.d(new System.Action(this.f));
        }

        private void h()
        {
            this.l.Content = e.c("Login");
            this.m.Content = e.c("Password");
            this.t.Content = e.c("AutoLogin");
            this.s.Content = e.c("SavePassword");
            this.x.Content = e.c("OfflineMode");
            this.u.Text = e.c("ForgotPassword");
            this.v.Text = e.c("Registration");
            this.i.Header = e.c("CheckIP");
            this.h.Header = e.c("Show");
            this.j.Header = e.c("Exit");
        }

        [CompilerGenerated]
        private static void h(object A_0)
        {
            ConfigManager.j();
        }

        public void i()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
            }
        }

        [CompilerGenerated]
        private void i(object A_0)
        {
            this.g();
        }

        [DebuggerNonUserCode]
        public void InitializeComponent()
        {
            if (!this.z)
            {
                this.z = true;
                Uri resourceLocator = new Uri("/TheSafety;component/mainwindow.xaml", UriKind.Relative);
                Application.LoadComponent(this, resourceLocator);
            }
        }

        [CompilerGenerated]
        private static void j(object A_0)
        {
            MessageBox.Show(e.c("InvalidLoginAndPassword"));
        }

        [CompilerGenerated]
        private void k(object A_0)
        {
            ConfigManager.d(new System.Action(this.f));
        }

        [CompilerGenerated]
        private static void l(object A_0)
        {
            NewsManager.d();
        }

        private void lblForgot_MouseLeftButtonUp(object A_0, MouseButtonEventArgs A_1)
        {
            Process.Start("https://thesafety.us/billing/recover/");
        }

        private void lblRegistration_MouseLeftButtonUp(object A_0, MouseButtonEventArgs A_1)
        {
            Process.Start("https://thesafety.us/billing/signup/");
        }

        [CompilerGenerated]
        private static void m(object A_0)
        {
            ConfigManager.j();
        }

        private void MenuItemExit_Click(object A_0, RoutedEventArgs A_1)
        {
            base.Close();
        }

        private void MenuItemShow_Click(object A_0, RoutedEventArgs A_1)
        {
            if ((AgentUser.a() != null) && (base.WindowState == WindowState.Minimized))
            {
                if (ConfigManager.o() == null)
                {
                    ConfigManager.a(new MainMenuPanel());
                    ConfigManager.o().b(new AgentMessageHandler(this.a));
                    ConfigManager.o().b(new AgentExitHandler(this.a));
                }
                ConfigManager.o().Visibility = Visibility.Visible;
            }
            else
            {
                base.Show();
                base.WindowState = WindowState.Normal;
                base.Activate();
            }
        }

        [CompilerGenerated]
        private void n(object A_0)
        {
            this.g();
        }

        private void NeedPasswordAndLogin(object A_0, NeedLoginAndPasswordEventArgs A_1)
        {
            <>c__DisplayClass37 class2;
            NeedLoginAndPasswordEventArgs a = A_1;
            this.b.Send(new SendOrPostCallback(class2.b), null);
        }

        [CompilerGenerated]
        private void o(object A_0)
        {
            this.e.IsEnabled = false;
        }

        protected override void OnClosing(CancelEventArgs A_0)
        {
            ConfigManager.e("flusher");
            base.OnClosing(A_0);
        }

        [CompilerGenerated]
        private void p(object A_0)
        {
            SendOrPostCallback d = null;
            SendOrPostCallback callback2 = null;
            SendOrPostCallback callback3 = null;
            SendOrPostCallback callback4 = null;
            SendOrPostCallback callback5 = null;
            SendOrPostCallback callback6 = null;
            if (ConfigManager.a())
            {
                if (d == null)
                {
                    d = new SendOrPostCallback(this.o);
                }
                this.b.Send(d, null);
                bool flag = false;
                if (!ConfigManager.r())
                {
                    AgentUser.a(WebRequestManager.a((A_0 as string[])[0], (A_0 as string[])[1], out flag));
                    if (AgentUser.a() != null)
                    {
                        if (callback2 == null)
                        {
                            callback2 = new SendOrPostCallback(this.n);
                        }
                        this.b.Send(callback2, null);
                        if (aa == null)
                        {
                            aa = new SendOrPostCallback(MainWindow.m);
                        }
                        this.b.Send(aa, null);
                        if ((AgentUser.a().b() != LicenseType.Limited) && (AgentUser.a() != null))
                        {
                            if (ab == null)
                            {
                                ab = new SendOrPostCallback(MainWindow.l);
                            }
                            this.b.Send(ab, null);
                        }
                        if (((ConfigManager.b("autoconnection") != null) && (ConfigManager.b("autoconnection") != "0")) && !string.IsNullOrWhiteSpace(ConfigManager.b("autoconnectconfig")))
                        {
                            if (callback3 == null)
                            {
                                callback3 = new SendOrPostCallback(this.k);
                            }
                            this.b.Send(callback3, null);
                        }
                    }
                    else if (!flag)
                    {
                        if (ac == null)
                        {
                            ac = new SendOrPostCallback(MainWindow.j);
                        }
                        this.b.Send(ac, null);
                    }
                }
                else
                {
                    AgentUser.a(new AgentUser());
                    if (callback4 == null)
                    {
                        callback4 = new SendOrPostCallback(this.i);
                    }
                    this.b.Send(callback4, null);
                    if (ad == null)
                    {
                        ad = new SendOrPostCallback(MainWindow.h);
                    }
                    this.b.Send(ad, null);
                    if (((ConfigManager.b("autoconnection") != null) && (ConfigManager.b("autoconnection") != "0")) && !string.IsNullOrWhiteSpace(ConfigManager.b("autoconnectconfig")))
                    {
                        if (callback5 == null)
                        {
                            callback5 = new SendOrPostCallback(this.g);
                        }
                        this.b.Send(callback5, null);
                    }
                }
                if (callback6 == null)
                {
                    callback6 = new SendOrPostCallback(this.f);
                }
                this.b.Send(callback6, null);
            }
            else
            {
                MessageBox.Show(e.c("Network_is_unavaible"));
            }
        }

        [CompilerGenerated]
        private void q(object A_0)
        {
            <>c__DisplayClass18 class2;
            object a = A_0;
            this.b.Send(new SendOrPostCallback(class2.c), null);
        }

        [CompilerGenerated]
        private void r(object A_0)
        {
            this.e.IsEnabled = true;
        }

        [CompilerGenerated]
        private void s(object A_0)
        {
            this.e.IsEnabled = false;
        }

        [DllImport("kernel32.dll")]
        private static extern bool SetProcessWorkingSetSize(IntPtr A_0, int A_1, int A_2);
        private void ShowPassword_Click(object A_0, MouseButtonEventArgs A_1)
        {
            if (this.o.Visibility == Visibility.Visible)
            {
                this.y.Visibility = Visibility.Visible;
                this.y.Text = this.o.Password;
                this.o.Visibility = Visibility.Hidden;
                this.q.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/lock_16x16.gif"));
            }
            else
            {
                this.o.Visibility = Visibility.Visible;
                this.o.Password = this.y.Text;
                this.y.Visibility = Visibility.Hidden;
                this.q.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/view_16x16.gif"));
            }
        }

        private void trayIco_TrayLeftMouseUp(object A_0, RoutedEventArgs A_1)
        {
            if ((AgentUser.a() != null) && (base.WindowState == WindowState.Minimized))
            {
                if (ConfigManager.o() == null)
                {
                    ConfigManager.a(new MainMenuPanel());
                    ConfigManager.o().b(new AgentMessageHandler(this.a));
                    ConfigManager.o().b(new AgentExitHandler(this.a));
                }
                ConfigManager.o().Visibility = Visibility.Visible;
            }
            else
            {
                base.Show();
                base.WindowState = WindowState.Normal;
                base.Activate();
            }
        }

        private void txtLogin_GotFocus(object A_0, RoutedEventArgs A_1)
        {
            (A_0 as TextBox).SelectAll();
        }

        private void txtLogin_PreviewMouseDown(object A_0, MouseButtonEventArgs A_1)
        {
            TextBox box = A_0 as TextBox;
            if (!box.IsFocused)
            {
                box.Focus();
                box.SelectAll();
                A_1.Handled = true;
            }
        }

        private void txtPassword_GotFocus(object A_0, RoutedEventArgs A_1)
        {
            (A_0 as PasswordBox).SelectAll();
        }

        private void txtPassword_PreviewMouseDown(object A_0, MouseButtonEventArgs A_1)
        {
            PasswordBox box = A_0 as PasswordBox;
            if (!box.IsFocused)
            {
                box.Focus();
                box.SelectAll();
                A_1.Handled = true;
            }
        }

        private void txtPasswordO_GotFocus(object A_0, RoutedEventArgs A_1)
        {
            (A_0 as TextBox).SelectAll();
        }

        private void txtPasswordO_PreviewMouseDown(object A_0, MouseButtonEventArgs A_1)
        {
            TextBox box = A_0 as TextBox;
            if (!box.IsFocused)
            {
                box.Focus();
                box.SelectAll();
                A_1.Handled = true;
            }
        }

        private void VPNConnection_StateChanged(object A_0, StateChangedEventArgs A_1)
        {
            SendOrPostCallback d = null;
            SendOrPostCallback callback2 = null;
            SendOrPostCallback callback3 = null;
            SendOrPostCallback callback4 = null;
            SendOrPostCallback callback5 = null;
            switch (A_1.NewState.ConnectionState)
            {
                case VPNConnectionState.Initializing:
                    if (d == null)
                    {
                        d = new SendOrPostCallback(this.e);
                    }
                    this.b.Send(d, null);
                    return;

                case VPNConnectionState.Running:
                    if (callback2 == null)
                    {
                        callback2 = new SendOrPostCallback(this.d);
                    }
                    this.b.Send(callback2, null);
                    return;

                case VPNConnectionState.Stopping:
                    if (callback4 == null)
                    {
                        callback4 = new SendOrPostCallback(this.b);
                    }
                    this.b.Send(callback4, null);
                    return;

                case VPNConnectionState.Stopped:
                    if (callback3 == null)
                    {
                        callback3 = new SendOrPostCallback(this.c);
                    }
                    this.b.Send(callback3, null);
                    return;

                case VPNConnectionState.Error:
                    if (callback5 == null)
                    {
                        callback5 = new SendOrPostCallback(this.a);
                    }
                    this.b.Send(callback5, null);
                    return;
            }
        }

        private void Window_Closing(object A_0, CancelEventArgs A_1)
        {
            System.Action action = null;
            System.Action action2 = null;
            ConfigManager.f();
            this.g.Dispose();
            ConfigManager.b();
            ConfigManager.n();
            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}");
            if (key != null)
            {
                bool flag = false;
                foreach (string str in key.GetSubKeyNames())
                {
                    try
                    {
                        if ((str.ToLower().Trim() != "properties") && ("tap0901" == key.OpenSubKey(str).GetValue("ComponentId", "").ToString().ToLower().Trim()))
                        {
                            flag = true;
                            break;
                        }
                    }
                    catch (Exception exception)
                    {
                        ConfigManager.a("Window_Closing", exception);
                    }
                }
                if (flag && (MessageBox.Show(e.c("UninstallTap"), e.c("UninstallTapHeader"), MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes))
                {
                    if (action == null)
                    {
                        action = new System.Action(this.c);
                    }
                    if (action2 == null)
                    {
                        action2 = new System.Action(this.b);
                    }
                    ConfigManager.a(action, action2);
                }
            }
        }

        private void Window_KeyUp(object A_0, KeyEventArgs A_1)
        {
            if (A_1.Key == Key.Return)
            {
                this.btnLogin_click(A_0, null);
            }
        }

        private void Window_Loaded(object A_0, RoutedEventArgs A_1)
        {
            <>c__DisplayClass6 class2;
            this.b = SynchronizationContext.Current;
            this.t.IsChecked = new bool?(ConfigManager.b("autologin") != "0");
            this.s.IsChecked = new bool?(ConfigManager.b("savepass") != "0");
            if ((ConfigManager.b("savepass") != "0") && (ConfigManager.b("mypass") != null))
            {
                this.o.Password = Encoding.UTF8.GetString(Convert.FromBase64String(ConfigManager.b("mypass")));
                this.y.Text = Encoding.UTF8.GetString(Convert.FromBase64String(ConfigManager.b("mypass")));
            }
            if ((ConfigManager.b("savepass") != "0") && (ConfigManager.b("mylogin") != null))
            {
                this.n.Text = Encoding.UTF8.GetString(Convert.FromBase64String(ConfigManager.b("mylogin")));
            }
            this.n.Focus();
            System.Timers.Timer a = new System.Timers.Timer(300.0);
            a.Elapsed += new ElapsedEventHandler(class2.c);
            a.Start();
        }

        private void Window_StateChanged(object A_0, EventArgs A_1)
        {
            if (base.WindowState == WindowState.Minimized)
            {
                base.Hide();
            }
            else
            {
                this.t.IsChecked = new bool?(ConfigManager.b("autologin") != "0");
                this.s.IsChecked = new bool?(ConfigManager.b("savepass") != "0");
            }
        }

        public string CurrentIP
        {
            get
            {
                return base.GetValue(c).ToString();
            }
            set
            {
                base.SetValue(c, value);
                this.g.a("TheSafety.US OpenVPN \n" + e.c("MyIp") + " " + value);
                this.b(value);
            }
        }
    }
}

